###########################################################################
#
#   makefile
#
#   Makefile for building SDLMAME Mac OS X Universal binaries
#
#   Copyright (c) Anthony Smith
#   Visit http://code.google.com/p/mess-universal for licensing and usage restrictions.
#
###########################################################################

#-------------------------------------------------
# version: 1.0b1
#-------------------------------------------------

#
# Possible ARCH settings
#
# i386
# ppc
# universal
#

ifndef ARCH
ARCH = universal
endif

MV = @mv

all: build

build:
ifeq ($(ARCH),i386)
	$(MAKE) -f makefile.sdl TARGETOS=macosx OBJ=$(ARCH)/obj BUILD_EXPAT=0 BUILD_ZLIB=0
endif
ifeq ($(ARCH),ppc)
	$(MAKE) -f makefile.sdl TARGETOS=macosx OBJ=$(ARCH)/obj BUILD_EXPAT=0 BUILD_ZLIB=0 BIGENDIAN=1
endif
ifeq ($(ARCH),universal)
	$(MAKE) ARCH=i386
	$(MAKE) ARCH=ppc
	@mkdir universal
	@echo Creating mess Universal binary...
	@lipo -create i386/mess ppc/mess -output universal/mess
	@echo Creating testkeys Universal binary...
	@lipo -create i386/testkeys ppc/testkeys -output universal/testkeys
	@echo Creating imgtool Universal binary...
	@lipo -create i386/imgtool ppc/imgtool -output universal/imgtool
	@echo Creating castool Universal binary...
	@lipo -create i386/castool ppc/castool -output universal/castool
	@echo Creating messtest Universal binary...
	@lipo -create i386/messtest ppc/messtest -output universal/messtest
	@echo Creating dat2html Universal binary...
	@lipo -create i386/dat2html ppc/dat2html -output universal/dat2html
	@echo Creating romcmp Universal binary...
	@lipo -create i386/romcmp ppc/romcmp -output universal/romcmp
	@echo Creating chdman Universal binary...
	@lipo -create i386/chdman ppc/chdman -output universal/chdman
	@echo Creating jedutil Universal binary...
	@lipo -create i386/jedutil ppc/jedutil -output universal/jedutil
	@echo Creating ldresample Universal binary...
	@lipo -create i386/ldresample ppc/ldresample -output universal/ldresample
	@echo Creating ldverify Universal binary...
	@lipo -create i386/ldverify ppc/ldverify -output universal/ldverify
	@echo Creating regrep Universal binary...
	@lipo -create i386/regrep ppc/regrep -output universal/regrep
	@echo Creating srcclean Universal binary...
	@lipo -create i386/srcclean ppc/srcclean -output universal/srcclean
	@echo Creating src2html Universal binary...
	@lipo -create i386/src2html ppc/src2html -output universal/src2html
endif
ifneq ($(ARCH),universal)
	@echo Moving mess...
	$(MV) mess $(ARCH)/mess
	@echo Moving testkeys...
	$(MV) testkeys $(ARCH)/testkeys
	@echo Moving imgtool...
	$(MV) imgtool $(ARCH)/imgtool
	@echo Moving castool...
	$(MV) castool $(ARCH)/castool
	@echo Moving messtest...
	$(MV) messtest $(ARCH)/messtest
	@echo Moving dat2html...
	$(MV) dat2html $(ARCH)/dat2html
	@echo Moving romcmp...
	$(MV) romcmp $(ARCH)/romcmp
	@echo Moving chdman...
	$(MV) chdman $(ARCH)/chdman
	@echo Moving jedutil...
	$(MV) jedutil $(ARCH)/jedutil
	@echo Moving ldresample...
	$(MV) ldresample $(ARCH)/ldresample
	@echo Moving ldverify...
	$(MV) ldverify $(ARCH)/ldverify
	@echo Moving regrep...
	$(MV) regrep $(ARCH)/regrep
	@echo Moving srcclean...
	$(MV) srcclean $(ARCH)/srcclean
	@echo Moving src2html...
	$(MV) src2html $(ARCH)/src2html
endif

clean:
ifeq ($(ARCH),i386)
	@echo Deleting i386...
	@$(RM) -r i386
endif
ifeq ($(ARCH),ppc)
	@echo Deleting ppc...
	@$(RM) -r ppc
endif
ifeq ($(ARCH),universal)
	@$(MAKE) clean ARCH=i386
	@$(MAKE) clean ARCH=ppc
	@echo Deleting universal...
	@$(RM) -r universal
endif